// components/user-data-introduction/user-data-introduction.js
const app = getApp()
import util from '../../utils/util'
const userDao = require('../../dao/userDao')
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    textarea: ''
  },
  lifetimes: {
    ready() {
      this.setData({
        textarea: app.data.currentUser.introduction,
      })
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    bindFormSubmit(e) {
      console.log('form发生了submit事件，', e.detail.value.textarea)
      userDao.update(app.data.currentUser._id, {introduction: e.detail.value.textarea, updateTime: new Date()}).then( res => {
        console.log(res)
        app.data.currentUser.introduction = e.detail.value.textarea
        util.setCache(app.keys.currentUser, app.data.currentUser)
        wx.showToast({
          title: '修改成功',
        })
      })
    },
  }
})
